package my.action.authentication;
import javax.servlet.http.*;
import my.controller.*;
import my.db.DAO.AuthenticationDAO;
import my.db.DTO.AuthenticationDTO;
public class AuthenticationAddAction implements  Action{
	 public ActionForward execute(HttpServletRequest request,HttpServletResponse response) throws Exception{
		
		 //Fields
		 	AuthenticationDAO autDAO=new AuthenticationDAO();
			AuthenticationDTO dto=null;
		   	ActionForward forward=new ActionForward();
		   	boolean result=true;
		   	String name=request.getParameter("username");
   			String pwd=request.getParameter("userpwd");
   			String position="author";
   		//Set value and checking condition
	   		try{   			
	   			
	   			dto.setAccountName(name);
	   			dto.setAccountPassword(pwd);
	   			dto.setPosition(position);
	   			result=autDAO.addAccount(dto);
	   			forward.setRedirect(false);
	   			if(result==true){   		 				
	   				forward.setPath("./addaccount.jsp?error=successfully added");
	   			}else{
	   				forward.setPath("./addaccount.jsp?error=unsuccessfully added");
	   			}
	  		}catch(Exception ex){
	  			//System.out.println(ex);
	   		}
	  		return forward;
		}  	
}